/********************************
 * manager for epoll and mod add del the events
 *
 * created by dirkcai
 * *******************************/


#ifndef EPOLLMANAGER_H
#define EPOLLMANAGER_H

#include <sys/types.h>
#include <sys/socket.h>
#include <sys/epoll.h>
#include <assert.h>
#include <unistd.h>

class BufferSocket;

class EpollManager
{
public:
	EpollManager( int listenfd, int iEpollSize, int iWaitSize );
	~EpollManager();
	int Init();
	int WaitEvents( int timeout );
	int AddEvent( int connfd, int iEventType, BufferSocket * ptBufSocket );
	int DelEvent(int connfd, int iEventType, BufferSocket * ptBufSocket );
	int Mod2W( int connfd , BufferSocket * ptBufSocket );
	int Mod2R( int connfd , BufferSocket * ptBufSocket );
	epoll_event * GetEventByPos( int index );
	int GetListenFd();

private:
	int m_epollfd;
	int m_iEpollSize;
	int m_listenfd;
	int m_iEpoll_Mode;
	int m_iWaitSize;
	int m_iNfds;
	struct epoll_event *  m_ptEvents;
};

#endif

